package it.unina.android.trip_track.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import it.unina.android.trip_track.database.dao.PercorsoDAO;
import it.unina.android.trip_track.database.dao.TodoDAO;

/**
 * Creates application database.
 * 
 * @author itcuties
 *
 */
public class SQLiteHelper extends SQLiteOpenHelper {

    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "todos_db";

	public SQLiteHelper(Context context) {
		// Databse: todos_db, Version: 1
		super(context, DATABASE_NAME, null, 1);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Execute create table SQL
		db.execSQL(TodoDAO.CREATE_TABLE);
        db.execSQL(PercorsoDAO.CREATE_TABLE);
	}

	/**
	 * Recreates table
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) {
		// DROP table
		db.execSQL(TodoDAO.UPGRADE_TABLE);
        db.execSQL(PercorsoDAO.UPGRADE_TABLE);
		// Recreate table
		onCreate(db);
	}
	
}
